package com.example.demo.Exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@ControllerAdvice
public class CustomExceptionHandler {
    @ExceptionHandler(Exception.class)
    public void uploadException(MaxUploadSizeExceededException e, HttpServletResponse resq) throws IOException
    {
        resq.setContentType("text/html;charset=utf-8");
        PrintWriter pw =resq.getWriter();
        pw.write("文件大小超出限制");
        pw.flush();
        pw.close();
    }
  /*  @ExceptionHandler(MaxUploadSizeExceededException.class)
    public ModelAndView uploadException(MaxUploadSizeExceededException e)throws IOException{
        ModelAndView mv = new ModelAndView();
        mv.addObject("msg","文件大小超出限制");
        mv.setViewName("error");
        return mv;
    }*/

}

